package com.chujiekeji.test.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;

import com.chujiekeji.test.BaseApplication;
import com.chujiekeji.test.R;
import com.chujiekeji.test.account.AccountHelper;
import com.chujiekeji.test.activity.LoginActivity;
import com.chujiekeji.test.fragment.base.BaseGeneralListFragment;
import com.chujiekeji.test.fragment.base.BaseGeneralRecyclerFragment;
import com.chujiekeji.test.fragment.base.BaseViewPagerFragment;
import com.chujiekeji.test.interf.OnTabReselectListener;
import com.chujiekeji.test.fragment.friend.FenSiFragment;
import com.chujiekeji.test.fragment.friend.PengYouFragment;
import com.chujiekeji.test.fragment.friend.GuanZhuFragment;

/**
 * Created by fei
 * on 2016/9/5.
 * <p>
 * Changed qiujuer
 * on 2016/9/5.
 */
public class FriendFragment extends BaseViewPagerFragment implements OnTabReselectListener {
    private Bundle getBundle(int catalog) {
        Bundle bundle = new Bundle();
        bundle.putInt("friend_type", catalog);
        return bundle;
    }

    @Override
    public void onTabReselect() {

        if (mBaseViewPager != null) {
            BaseViewPagerAdapter pagerAdapter = (BaseViewPagerAdapter) mBaseViewPager.getAdapter();
            Fragment fragment = pagerAdapter.getCurFragment();
            if (fragment != null) {
                if (fragment instanceof BaseGeneralListFragment)
                    ((BaseGeneralListFragment) fragment).onTabReselect();
                else if (fragment instanceof BaseGeneralRecyclerFragment)
                    ((BaseGeneralRecyclerFragment) fragment).onTabReselect();
            }
        }
    }

    @Override
    protected PagerInfo[] getPagers() {
        return new PagerInfo[]{
                new PagerInfo("我的关注", GuanZhuFragment.class,
                        getBundle(1)),
                new PagerInfo("我的粉丝", FenSiFragment.class,
                        getBundle(2)),
                new PagerInfo("我的好友", PengYouFragment.class,
                        getBundle(3))
        };
    }

    @Override
    protected int getTitleRes() {
        return R.string.connection;
    }

    @Override
    protected int getIconRes() {
        return 0;
    }

    @Override
    protected View.OnClickListener getIconClickListener() {
        return new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        };
    }
    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser){
        super.setUserVisibleHint(isVisibleToUser);
        if (isVisibleToUser && !AccountHelper.isLogin()){
            BaseApplication.get().start(getActivity(),LoginActivity.class);
        }

    }
}
